package com.reverie.controller;

import com.reverie.common.pojo.CommonResult;
import com.reverie.entity.PopConfig;
import com.reverie.service.IPopConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("popConfig")
public class PopConfigController {

    @Resource
    private IPopConfigService popConfigService;

    @GetMapping("list")
    public CommonResult<List<PopConfig>> queryAll() {
        return CommonResult.data(popConfigService.list());
    }

    @PostMapping("save")
    public CommonResult<Boolean> save(@RequestBody PopConfig popConfig) {
        return CommonResult.data(popConfigService.saveOrUpdate(popConfig));
    }

    @PostMapping("delete")
    public CommonResult<Boolean> delete(@RequestBody PopConfig popConfig) {
        PopConfig config = popConfigService.getById(popConfig.getId());
        if(config != null){
            return CommonResult.data(popConfigService.removeById(config.getId()));
        }
        return CommonResult.data(true);
    }

}
